package com.jingdianjichi.auth.domain.service.Impl;

import com.alibaba.fastjson.JSON;
import com.jingdianjichi.auth.common.enums.IsDeletedFlagEnum;
import com.jingdianjichi.auth.domain.bo.AuthRoleBO;
import com.jingdianjichi.auth.domain.bo.AuthRolePermissionBO;
import com.jingdianjichi.auth.domain.convert.AuthRoleBOConvert;
import com.jingdianjichi.auth.domain.convert.AuthRolePermissionBOConvert;
import com.jingdianjichi.auth.domain.service.AuthRoleDomainService;
import com.jingdianjichi.auth.domain.service.AuthRolePermissionDomainService;
import com.jingdianjichi.auth.infra.bastic.entity.AuthPermission;
import com.jingdianjichi.auth.infra.bastic.entity.AuthRole;
import com.jingdianjichi.auth.infra.bastic.entity.AuthRolePermission;
import com.jingdianjichi.auth.infra.bastic.service.AuthRolePermissionService;
import com.jingdianjichi.auth.infra.bastic.service.AuthRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.security.Permission;
import java.util.LinkedList;
import java.util.List;

/**
 * ClassName:AuthRoleDomainServiceImpl
 * Package:com.jingdianjichi.auth.domain.service.Impl
 * Description:
 *
 * @Author fst
 * @Create 2024/10/10 14:58
 * @Version 1.0
 */
@Slf4j
@Service
public class AuthRolePermissionDomainServiceImpl implements AuthRolePermissionDomainService
{
    @Resource
    private AuthRolePermissionService authRolePermissionService;



    public void add(AuthRolePermissionBO authRolePermissionBO)
    {
        if(log.isInfoEnabled())
        {
            log.info("AuthRolePermissionDomainServiceImpl.add.Bo:{}", JSON.toJSONString(authRolePermissionBO));
        }


        List<AuthRolePermission> authRolePermissionList =new LinkedList<>();
        Long roleId= authRolePermissionBO.getRoleId();
        for (Integer id : authRolePermissionBO.getPermissionIdList()) {
            AuthRolePermission authRolePermission=new AuthRolePermission();

            authRolePermission.setRoleId(roleId);
            authRolePermission.setPermissionId(Long.valueOf(id));
            authRolePermission.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
            authRolePermissionList.add(authRolePermission);
        }

        authRolePermissionService.insertBacth(authRolePermissionList);

    }

}
